package com.hqyj.javaGraduation.hotel.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hqyj.javaGraduation.hotel.pojo.UtMenuInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;

@Mapper
@Repository
public interface UtMenuInfoDao extends BaseMapper<UtMenuInfo> {

    // 客户点菜
    @Insert("insert into ut_menu_info (user_id,table_id,menu_id,menu_name,ut_info_date,menu_cost,menu_price,menu_state) values" +
            "(#{utMenuInfo.userId},#{utMenuInfo.tableId},#{utMenuInfo.menuId},#{utMenuInfo.menuName}," +
            "#{utMenuInfo.utInfoDate},#{utMenuInfo.menuCost},#{utMenuInfo.menuPrice},#{utMenuInfo.menuState})")
    int insertMenuByUserId(@Param("utMenuInfo") UtMenuInfo utMenuInfo);

    // 查询客户购物车信息
    @Select("select * from ut_menu_info where table_id = #{utMenuInfo.tableId} and menu_state = '加入购物车'")
    HashMap<String, Object> queryAllMenuInfo(@Param("utMenuInfo") UtMenuInfo utMenuInfo);

    // 查询当前菜品订单信息 user_id = #{utMenuInfo.userId} and
    @Select("select * from ut_menu_info where table_id = #{utMenuInfo.tableId} and menu_id = #{utMenuInfo.menuId}")
    UtMenuInfo queryMenuNumber(@Param("utMenuInfo") UtMenuInfo utMenuInfo);

    // 客户加菜 user_id = #{utMenuInfo.userId} and
    @Update("UPDATE ut_menu_info set menu_num = menu_num+1 where " +
            "table_id = #{utMenuInfo.tableId} and menu_id = #{utMenuInfo.menuId}")
    int addMenuByUtMenuInfo(@Param("utMenuInfo") UtMenuInfo utMenuInfo);

    // 客户从购物车减少菜品订购数量  user_id = #{utMenuInfo.userId} and
    @Update("UPDATE ut_menu_info set menu_num = menu_num-1 where " +
            "table_id = #{utMenuInfo.tableId} and menu_id = #{utMenuInfo.menuId}")
    int deleteMenuByUtMenuInfo(@Param("utMenuInfo") UtMenuInfo utMenuInfo);

    // 删除购物车中的菜品订单信息
    @Delete("delete from ut_menu_info where ut_info_id = #{utMenuInfo.utInfoId}")
    int deleteMenuInfo(@Param("utMenuInfo") UtMenuInfo utMenuInfo);

    // 给厨房打印订单
    @Select("select * from ut_menu_info")
    HashMap<String, Object> queryAllUtMenuInfo(UtMenuInfo utMenuInfo);

    // 付款总金额  /*user_id=#{utMenuInfo.userId} and*/
    @Select("SELECT * from ut_menu_info where table_id = #{utMenuInfo.tableId}")
    List<UtMenuInfo> queryAllPrice(@Param("utMenuInfo")UtMenuInfo utMenuInfo);

    // 修改支付状态
    @Update("update ut_menu_info set menu_state = '已支付' where table_id = #{utMenuInfo.tableId}")
    int updateUtMenuInfoState(@Param("utMenuInfo")UtMenuInfo utMenuInfo);
}
